package com.apps.ftapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.apps.ftapp.R;
import com.apps.ftapp.adapter.MyLessonCacheAdapter;
import com.apps.ftapp.db.Lesson;
import com.apps.ftapp.util.ActivitySkipUtil;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 我的缓存课程
 */
public class MyLessonCacheActivity extends BaseActivity {

    @BindView(R.id.listView)
    ListView listView;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout refreshLayout;

    private List<Lesson> lessonList = new ArrayList();
    private MyLessonCacheAdapter myLessonCacheAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_lesson_cache);
        ButterKnife.bind(this);


        initView();


        setTitle("缓存课程");


        loadData();

    }

    private void loadData() {

        lessonList = DataSupport.findAll(Lesson.class);
        if (null != lessonList && lessonList.size() > 0) {
            myLessonCacheAdapter.addRes(lessonList);
        }

    }

    private void initView() {

        myLessonCacheAdapter = new MyLessonCacheAdapter(getApplicationContext(), lessonList);
        listView.setAdapter(myLessonCacheAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                HashMap hashMap = new HashMap();
                hashMap.put("id", lessonList.get(i).getLessonid());
                ActivitySkipUtil.skipAnotherActivity(MyLessonCacheActivity.this, MyLessonCacheDetailActivity.class, hashMap);
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
